package com.yunhe.openapi.controller;

import com.yunhe.common.model.ResultObject;
import com.yunhe.openapi.model.MeasRealtime;
import com.yunhe.openapi.service.MeasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 获取量测数据接口
 */
@RestController
@RequestMapping("/meas")
public class MeasController {

    @Autowired
    private MeasService measService;

    /**
     * 基于客户编码获取所有实时量测数据
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/realtime-all", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> realtimeAll(@RequestParam("customerId") String customerId){
        List<List<MeasRealtime>> list = measService.getRealTimeDataAll(customerId);
        ResultObject resultObject = new ResultObject(list);
        return new ResponseEntity<>(resultObject, HttpStatus.OK);
    }

    /**
     * 获取实时量数据测接口
     * @param customerId 客户编码
     * @param companyCode 公司编号
     * @param dataCode 点号编号
     * @return
     */
    @RequestMapping(value = "/realtime", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> realtime(@RequestParam("customerId") String customerId,
                                                 @RequestParam("companyCode") String companyCode,
                                                 @RequestParam(value = "dataCode", required = false) String dataCode){
        List<MeasRealtime> list = measService.getRealTimeData(customerId, companyCode, dataCode);
        ResultObject resultObject = new ResultObject(list);
        return new ResponseEntity<>(resultObject, HttpStatus.OK);
    }

    /**
     * 获取历史量测数据
     * @param customerId
     * @Param dtime 时间范围，如“20211006000000,20211008234500”
     * @return
     */
    @GetMapping(value = "/history")
    public ResponseEntity<ResultObject> history(@RequestParam("customerId") String customerId,
                                                @RequestParam("companyCode") String companyCode,
                                                @RequestParam("dtime") String dtime,
                                                @RequestParam(value = "dataCode", required = false) String dataCode){
        List<Map<String, Object>> list = measService.getHistoryData(customerId, companyCode, dataCode, dtime);
        ResultObject resultObject = new ResultObject(list);
        return new ResponseEntity<>(resultObject, HttpStatus.OK);
    }

}
